package com.woniu.controller;

import com.woniu.entity.Good;
import com.woniu.entity.GoodSearchParam;
import com.woniu.service.GoodService;
import com.woniu.util.PageData;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodController {
    @Autowired
    private GoodService goodService;

    @PostMapping("/update")
    public ResData<?> udpateGood(Integer id,Integer status){
        return goodService.updateGood(id, status);
    }

    @GetMapping("/delete")
    public ResData<?> deleteGood(Integer id){
        List<Integer> ids = new ArrayList<>();
        ids.add(id);
        return goodService.deleteGood(ids);
    }

    @PostMapping("/deleteBatch")
    public ResData<?> deleteBatch(@RequestBody List<Integer> ids){
        return goodService.deleteGood(ids);
    }

    @PostMapping("/queryGoods")
    public ResData<?> queryGoods(@RequestBody PageData<GoodSearchParam> pageData){
        return goodService.queryGoods(pageData);
    }

    @PostMapping("/addGood")
    public ResData<?> addGood(@RequestBody Good good){
        return goodService.addGood(good);
    }

    @GetMapping("/queryAllTypes")
    public ResData<?> queryAllTypes(){
        return goodService.queryAllGoodTypes();
    }


}
